package com.wq.feign.provider.controller;

import com.wq.feign.api.domain.Result;
import com.wq.feign.api.domain.request.ProductReq;
import com.wq.feign.provider.domain.entity.Product;
import com.wq.feign.provider.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    /**
     * 查询
     * @param id
     * @return
     */
    @GetMapping("/provider/get/{id}")
    public Product selectById(@PathVariable("id") Long id){
        return new Product(1L,"123",1);
        //return new Result(200, "查询成功", productService.selectById(id));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/provider/delete/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        return new Result(200, "删除成功", productService.deleteById(id));
    }

    /**
     * 修改
     * @param productReq
     * @return
     */
    @PostMapping("/provider/update")
    public Result updateProduct(@RequestBody ProductReq productReq){
        return new Result(200, "修改成功", productService.updateById(productReq.getId(), productReq.getName()));

    }

    /**
     * 新增
     * @return
     */
    @PutMapping( "product/provider/add")
    public Result insertById(@RequestBody Product product){
        return new Result(200, "修改成功", productService.insertOne(product));
    }
}

